package com.kmust.dream.wanderingdream.product.controller;

import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductProperty;
import com.kmust.dream.wanderingdream.product.service.ProductPropertyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product/property")
@Api(value = "商品属性对API")
public class ProductPropertyController {

    @Autowired
    ProductPropertyService productPropertyService;

    /**
     * 获取所有的属性对对象
     * @return resultBean
     */
    @ApiOperation(value = "获取所有的属性对对象",notes = "无参数")
    @GetMapping("/getAllProperties")
    public ResultBean getAllProperties() {
        return productPropertyService.getAllProperties();
    }


    /**
     * 通过主键获取属性对对象
     * @param id 主键
     * @return resultBean
     */
    @ApiOperation(value = "通过主键获取属性对对象",notes = "参数是主键")
    @GetMapping("/getPropertyById/{id}")
    public ResultBean getPropertyById(@PathVariable Integer id) {
        return productPropertyService.getPropertyById(id);
    }

    /**
     * 通过商品id获取属性对对象
     * @param productId 商品id
     * @return resultBean
     */
    @ApiOperation(value = "通过商品id获取属性对对象",notes = "参数是商品id")
    @GetMapping("/getPropertyByProductId/{productId}")
    public ResultBean getPropertyByProductId(@PathVariable Integer productId) {
        return productPropertyService.getPropertyByProductId(productId);
    }


    /**
     * 添加属性对对象
     * @param productProperty 属性对对象
     * @return resultBean
     */
    @ApiOperation(value = "添加属性对对象",notes = "参数是属性对对象json")
    @PostMapping("/addProductProperty")
    public ResultBean addProductProperty(@RequestBody ProductProperty productProperty) {
        return productPropertyService.addProductProperty(productProperty);
    }

    /**
     * 修改属性对
     * @param productProperty 属性对对象
     * @return resultBean
     */
    @ApiOperation(value = "修改属性对",notes = "参数是属性对对象json")
    @PutMapping("/updateProductProperty")
    public ResultBean updateProductProperty(@RequestBody ProductProperty productProperty) {
        return productPropertyService.updateProductProperty(productProperty);
    }

    /**
     * 根据主键删除属性对
     * @param id 主键
     * @return resultBean
     */
    @ApiOperation(value = "根据主键删除属性对",notes = "参数是主键")
    @DeleteMapping("/deleteProductPropertyById/{id}")
    public ResultBean deleteProductProperty(@PathVariable Integer id) {
        return productPropertyService.deleteProductProperty(id);
    }
}
